package com.attendcollatesys;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.WriteTable;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.attendcollatesys.entity.excel.ExcelATDayDetails;
import com.attendcollatesys.excel.style.AtDayDetailsStyleProcessor;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ExcelWrite {
    public static void main(String[] args) {

        WriteSheet sheet = EasyExcel.writerSheet("Sheet1").build();
        List<List<String>> head = new ArrayList<>();
        //ArrayList<String> maxhead = new ArrayList<String>();

       // maxhead.add("MAX");
       // head.add(maxhead);
// 动态生成列数
        //2024-01-02



        int columnCount = 10; // 假设生成 10 列
        for (int i = 0; i < columnCount; i++) {

            List<String> headerRow = new ArrayList<>();
            headerRow.add("主标题");
            headerRow.add("Column " + (i + 1));
            head.add(headerRow);

        }


// 写入表头


        List<List<Object>> data = new ArrayList<>();

// 模拟写入 10 行数据
        for (int i = 0; i < 10; i++) {
            List<Object> rowData = new ArrayList<>();
            for (int j = 0; j < columnCount; j++) {
                rowData.add("Data " + (i + 1) + "-" + (j + 1));
            }
            data.add(rowData);
        }

        // 头的策略
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        // 背景设置为红色
        headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontHeightInPoints((short)12);
        headWriteCellStyle.setWriteFont(headWriteFont);

        // 内容的策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
        contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        // 背景绿色
        contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
        WriteFont contentWriteFont = new WriteFont();
        // 字体大小
        contentWriteFont.setFontHeightInPoints((short)20);
        contentWriteCellStyle.setWriteFont(contentWriteFont);

        HorizontalCellStyleStrategy horizontalCellStyleStrategy =
                new HorizontalCellStyleStrategy(headWriteCellStyle,contentWriteCellStyle);

// 写入数据
        ExcelWriter excelWriter = EasyExcel.write("D:/File/work-6/1/10000022.xlsx").build();
        WriteSheet writeSheet = EasyExcel.writerSheet("11").needHead(Boolean.FALSE).build();
        WriteTable writeTable0 = EasyExcel.writerTable(0).head(head).registerWriteHandler(horizontalCellStyleStrategy).needHead(true).build();
        WriteTable writeTable1 = EasyExcel.writerTable(1).head(head).registerWriteHandler(horizontalCellStyleStrategy).needHead(true).build();
        //excelWriter.write()

        ArrayList<Object> temp = new ArrayList<>(2);

        for (int j = 0; j < 2; j++) {
            temp.add("");
        }

        excelWriter.write(data, writeSheet, writeTable0);

        excelWriter.write(temp, writeSheet);
        // 第二次写如也会创建头，然后在第一次的后面写入数据
        excelWriter.write(data, writeSheet, writeTable1);

        excelWriter.finish();



      //  EasyExcel.write("D:/File/work-6/1/output.xlsx").head(head).registerWriteHandler(horizontalCellStyleStrategy).sheet("hello").doWrite(objects);
      // EasyExcel.write("D:/File/work-6/1/output.xlsx").head(head).registerWriteHandler(horizontalCellStyleStrategy).sheet("hello").doWrite(data);


    }

    public static class v{
        private static String ec;


        @ExcelProperty()
        private String d;
    }
}
